package com.sy.musicapp.intent.network

import com.sy.musicapp.intent.service.MusicService
import com.sy.musicapp.intent.service.PlaylistService
import com.sy.musicapp.intent.service.SearchService
import com.sy.musicapp.intent.service.UserService
import retrofit2.awaitResponse

object MusicAppNetwork {
    private val userService = ServiceCreator.create<UserService>()
    private val searchService = ServiceCreator.create<SearchService>()
    private val playlistService = ServiceCreator.create<PlaylistService>()
    private val musicService = ServiceCreator.create<MusicService>()

    /** 用户 */
    suspend fun loginWithPhone(phone: String, pwd: String) =
        userService.loginWithPhone(phone, pwd).awaitResponse()

    suspend fun loginWithEmail(email: String, pwd: String) =
        userService.loginWithPhone(email, pwd).awaitResponse()

    suspend fun updateStatus() = userService.updateStatus().awaitResponse()
    suspend fun getUserInfo() = userService.getUserInfo().awaitResponse()
    suspend fun logout() = userService.logout().awaitResponse()

    /** 海报 */
    suspend fun getBanner() = userService.getBanner().awaitResponse()

    /** 搜索 */
    suspend fun getHotkey() = searchService.getHotkey().awaitResponse()
    suspend fun getSearchResult(key: String) = searchService.getSearchResult(key).awaitResponse()

    /** 歌单 */
    suspend fun getPlaylist(uid: String) = playlistService.getPlaylist(uid).awaitResponse()
    suspend fun addPlaylist(name: String) = playlistService.addPlaylist(name).awaitResponse()
    suspend fun delPlaylist(id: String) = playlistService.delPlaylist(id).awaitResponse()
    suspend fun getPlaylistMusic(id: String) = playlistService.getPlaylistMusic(id).awaitResponse()

    /** 歌曲 */
    suspend fun getRecomMusic() = musicService.getRecomMusic().awaitResponse()
    suspend fun getMusicDetail(id: String, br: String = "320000") =
        musicService.getMusicDetail(id, br).awaitResponse()

    suspend fun getLyric(id: String) = musicService.getLyric(id).awaitResponse()
}